
package com.sxtyxt.volley;

import com.sxtyxt.online.R;
import com.sxtyxt.util.ToastUtil;
import com.sxtyxt.widget.LoadingDialog;

import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;

/**
 * 
 * @author 马海明
 * @created 马海明 2015年5月6日
 */
public class LoadingDialogResultListenerImpl implements ResultLinstener {

	private LoadingDialog dialog;
	private String tag;
	private Context context;
	/**
	 * 
	 */
	public LoadingDialogResultListenerImpl(Context context, String msg) {
		this.context = context;
		dialog = new LoadingDialog(context, R.style.dialog, msg);
		dialog.setCanceledOnTouchOutside(false);
		dialog.show();
		dialog.setOnCancelListener(new OnCancelListener() {

			@Override
			public void onCancel(DialogInterface dialog) {
				// VolleyUtils.cancelService(tag);
			}
		});
	}

	@Override
	public void onSuccess(String response) {
		if (dialog != null) {
			dialog.dismiss();
		}
		System.out.println(response);
	}

	@Override
	public void onServerError() {
		if (dialog != null) {
			dialog.dismiss();
		}
		ToastUtil.getInstance().showToast(context,"服务器错误");

	}

	@Override
	public void onIOError() {
		if (dialog != null) {
			dialog.dismiss();
		}
		ToastUtil.getInstance().showToast(context, "无法访问服务器,可能网络异常");
	}

	@Override
	public void onSetTag(String tag) {
		this.tag = tag;
	}

	@Override
	public void onTimeOutError() {

		if (dialog != null) {
			dialog.dismiss();
		}
		ToastUtil.getInstance().showToast(context, "访问超时，请重试");
	}

	@Override
	public void onNoConnectionError() {
		if (dialog != null) {
			dialog.dismiss();
		}
		ToastUtil.getInstance().showToast(context, "连接错误，可能访问地址有误");
	}

	@Override
	public void onError() {
		if (dialog != null) {
			dialog.dismiss();
		}
	}
}
